
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>生产派工取消编辑</title>
	<!-- import css and js --> 
	<%@ include file="/common/metaInput.jsp" %>  
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript" src="${ctx}/js/My97DatePicker/WdatePicker.js"></script>
	<script src="${ctx}/js/print/LodopFuncs.js" type="text/javascript"></script>
<script type="text/javascript">
var basic_Url="${ctx}/logic/prodetail";
var grid;
var print=false;
var checai=false;
$(function(){
	$("#inputForm").validate({			   
		onsubmit: true,
		 /*执行ajaxsubmit  */ 
	    submitHandler: function(editform) {
	        //alert(jsonInfo); 
	        try{			    		
	            url =  basic_Url+"/save.do";
	            var api = frameElement.api;
	        	var W = api.opener;
	        	var d=new Date($("#bizCreatorDate").val());
	        	var da=d.getFullYear()+'年'+(d.getMonth()+1)+'月'+(d.getDate())+'日';
	        	var obj={'zd004CustomerName':$("#zd004CustomerName").val(),'bizCreatorDate':da,'zd007SalesMan':$("#zd007SalesMan").val(),'zd003PiCode':$("#zd003PiCode").val(),'zd001FormCode':$("#zd001FormCode").val(),'zd009Remark':$("#zd009Remark").val(),'zhuguan':$("#zhuguan").val()};
	        	getReturnMessageThree(url,"inputForm",W.searchAP,"",obj,grid.getData(),print,'prodetail',false,checai);
	        }catch(e){
	        	alert(e);
	        }
	    }
	});
	
	grid = $("#dataGrid").ligerGrid({
	    columns: [{ display: 'ID', name: 'id', width: 1 , hide:true},
	              { display: '产品id', name: 'zd006MaterialsId', width: 1 , hide:true},
	              { display: '<font color="gray">产品编码</font>', name: 'zd006MaterialsCode',  width: 100},
				  { display: '<font color="gray">产品名称</font>', name: 'zd006MaterialsName', width: 100 },
				  { display: '<font color="gray">产品型号</font>', name: 'zd010MaterialsModel', width: 100},
				  { display: '<font color="gray">产品尺寸</font>', name: 'zd023MaterialsSize', width: 100},
				  { display: '<font color="gray">产品颜色</font>', name: 'zd026MaterialsColor', width: 100},
				  { display: '<font color="gray">产品材质</font>', name: 'zd027MaterialsQuality', width: 100},
				  { display: '<font color="gray">计量单位</font>', name: 'zd012MaterialsUnit', width: 60},
				  { display: '工序id', name: 'zd029Process', width: 80, hide : true},
				  { display: '<font color="gray">工序名称</font>', name: 'zd029ProcessName', width: 80},
				  { display: '生产车间id', name: 'zd028WorkShop', width: 80, hide : true},
				  { display: '<font color="gray">生产车间</font>', name: 'zd028WorkShopName', width: 80},
				  { display: '<font color="gray">订单数量</font>', name: 'zd030PlanQuantity', width: 80},
				  { display: '<font color="gray">派工数量</font>', name: 'zd013Quantity', width: 80},
				  { display: '<font color="gray">已取消数量</font>', name: 'zd019ReturnQuantity', width: 80,render:function(item){
					  if(item.zd019ReturnQuantity==undefined||item.zd019ReturnQuantity==null||item.zd019ReturnQuantity==""){
						  return "0";
					  }
	             	  return (1*item.zd019ReturnQuantity).toFixed(4);
	              }},
				  { display: '取消数量<font color="red">*</font>', name: 'zdTheQuantity', width: 80,editor : {type :'float'}},
				  { display: '单价', name: 'zd014Price', width: 80,editor : {type :'float'}},
				  { display: '人员code', name: 'zd007UseCode', width: 80, hide:true},
				  { display: '工作人员', name: 'zd008UseName', width: 80},
	              { display: '<font color="gray">产品描述</font>', name: 'zd021MaterialsDescription', width: 150}
	              ],
	              usePager: true,pageSize:1000,pageSizeOptions:[1000],
	              enabledEdit: true,enabledSort:true,
	              parms:[{ name : 'id' , value : '${prodetail.id}'}],
	              url : basic_Url+"/gridItems.do",
	              width: "100%", height:'90%', checkbox: true, rownumbers:true,
	              toolbar: { items: [
	                                 { line: true },
	                                 { text: '删除', click: deleteRow, img: '${ctx}/js/ligerUI/skins/icons/delete.gif' }
	                                ]
	                       }
	});
	
	//按钮是否可见
	var buttonUp = '${buttonUp}';
	if("yes"==buttonUp){
		$("#forView").hide();
		$("#forPrint").hide();
		$("#forSubmit").hide();
	}
	var upSave = '${prodetail.zd008WorkStatus}';
	if('PRODISPATDTL_YES'==upSave){
		$("#forSubmit").hide();
	}
	if($("#checai").val()=="yes"){
		checai=true;//是不是车裁车间
	}
}); 
//删除行
function deleteRow(){ 
	grid.deleteSelectedRow();
}
//提交
function submitForm(){
	var cRows = grid.getCheckedRows();
	 if(cRows==null||cRows.length==0){
		 $.dialog.alert("请选择要取消的工序！");
		 return false;
	 }
	 var ba = true;
	 for (var i = 0;i<cRows.length;i++){
		var row= cRows[i]; 
		if(undefined==row.zdTheQuantity||isNaN(row.zdTheQuantity)||row.zdTheQuantity<= 0){
	          $.dialog.alert("您第"+(i+1)+"行的“取消派工数量”不合法");
	          ba=false;
	          return false;
	       }
		if(row.zd013Quantity<(row.zdTheQuantity+row.zd019ReturnQuantity)){
			$.dialog.alert("您第"+(i+1)+"行的“取消派工数量”大于“派工数量”无法取消派工");
	        ba=false;
	        return false;
		}
	}
	jQuery.ajaxSettings.async = false;
	if (ba) {
		$("#itemdata").val(JSON.stringify(cRows));
		print=true;
		$("#inputForm").submit();
	}
 }
//打印
function PrintView(type){
	var data = grid.getData();//获取单据要打印数据
	var d=new Date($("#bizCreatorDate").val());
	var da=d.getFullYear()+'年'+(d.getMonth()+1)+'月'+(d.getDate())+'日';
	var obj={'zd004CustomerName':$("#zd004CustomerName").val(),'bizCreatorDate':da,'zd007SalesMan':$("#zd007SalesMan").val(),'zd003PiCode':$("#zd003PiCode").val(),'zd001FormCode':$("#zd001FormCode").val(),'zd009Remark':$("#zd009Remark").val(),'zhuguan':$("#zhuguan").val()};
	var isprint=false;
	if(type==2){
		isprint=true;
	}
	window.parent.parent.loadPrint(obj,data,'prodetail',isprint,$("#zd001FormCode").val(),checai);
		
}

</script>
</head>
<body>
<input id="bizCreatorDate" type="hidden" name="bizCreatorDate"  value='<fmt:formatDate value="${prodetail.bizCreatorDate}" pattern="yyyy-MM-dd" type="both" />'/>
<input id="zhuguan" type="hidden" value="${user.realName}" />
<form id="inputForm" action="" method="post">
<input type="hidden" id="id" name="id" value="${prodetail.id}"/>
<input type="hidden" id="bizVersion" name="bizVersion" value="${prodetail.bizVersion}"/>
<input type="hidden" id="itemdata" name="itemdata"/>
<input type="hidden" id="checai" value="${ccFlag}" />
<!-- 用于标识提交按钮 -->
 <div class="pageContent" >
    <div class="panel">
         <table class="TableBlock" align="center">
         	<tr>
               	<td>料单号:</td>
                 <td colspan="3">
                	<input type="text" id="zd001FormCode" name="zd001FormCode" readonly="readonly" style="width: 40%;"  value="${prodetail.zd001FormCode}"/>
                 </td>
            </tr>
         	<tr>
         		<td >生产调度单号:</td>
              	<td>
              		<input type="hidden" id="zd002SaleId" name="zd002SaleId" value="${prodetail.zd002SaleId}" />
             		<input type="text" id="zd002OriCode" name="zd002OriCode" class="required" readonly="readonly" style="width: 40%;" value="${prodetail.zd002OriCode}" />
                </td>
                <td >PI编号:</td>
               	<td>
               		<input type="text" id="zd003PiCode" name="zd003PiCode" class="required" readonly="readonly" style="width: 40%;" value="${prodetail.zd003PiCode}" />
               	</td>
         	</tr>
            <tr>
           		<td >客户编码:</td>
               	<td>
               		<input type="hidden" id="zd004CustomerId" name="zd004CustomerId" class="required" readonly="readonly" style="width: 40%;" value="${prodetail.zd004CustomerId}" />
              		<input type="text" id="zd004CustomerCode" name="zd004CustomerCode" class="required" readonly="readonly" style="width: 40%;" value="${prodetail.zd004CustomerCode}" />
               	</td>  
            	<td>客户名称:</td>
               	<td>
              		<input type="text" id="zd004CustomerName" name="zd004CustomerName" class="required" readonly="readonly" style="width: 40%;" value="${prodetail.zd004CustomerName}" />
               	</td>     
         	</tr>
         	   <tr>
           		<td >业务员:</td>
               	<td>
					<input id="zd007SalesMan" type="text" readonly="readonly" name="zd007SalesMan" value="${prodetail.zd007SalesMan}"/>
               	</td>  
            	<td >附件:</td>
   		           		<td>
   		           			<input type="button" value="查看附件..." onclick="uploadFileWindow('zd002SaleId','');" />
   		           		</td>
               	     
         	</tr>
         	<tr>
         		<td >备注:</td>
         		<td colspan="3"><input id="zd009Remark" name="zd009Remark" style="width: 40%;" value="${prodetail.zd009Remark}" /></td>
          	</tr>
          	<tr>
				<td colspan="4" style="margin-bottom: 10px;">
					<div id="dataGrid"></div>
				</td>
			</tr>
       	</table>               
   	</div>
    <div class="formBar">
	    <ul>
	    	<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="forView" onclick="PrintView(1);">打印预览</button></div></div></li>
	   		<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="forPrint" onclick="PrintView(2);">打印</button></div></div></li>
	    	<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="forSubmit" onclick="submitForm()">保存</button></div></div></li>
	    	<li><div class="button"><div class="buttonContent"><button type="button" class="print" onclick="CloseDialog()">关闭</button></div></div></li>
	    </ul>
   </div>    
 </div>
</form>
</body>
</html>

